package org.openkanban.client.util;

import org.openkanban.client.Main;
import org.openkanban.client.ui.board.BoardComponent;
import org.openkanban.client.ui.board.EnterBoardNameView;
import org.openkanban.client.ui.board.KanbanView;
import org.openkanban.shared.dto.BoardDto;

/**
 * The Main Panel of the Application. Used to handle cross dependencies between
 * UI components.
 */
public abstract class RootPanel {

    public static Main main;

    public static BoardComponent boardComponent = new BoardComponent();

    private static boolean editMode;

    /**
     * Sets some UI parameters to enable and disable board edit mode
     * 
     * @param isEditMode
     */
    public static void activateBoardEditMode(boolean isEditMode) {
	editMode = isEditMode;
	if (isEditMode) {
	    EnterBoardNameView enterBoardNameView = new EnterBoardNameView();

	    if (main.getBoard().getWhiteBoardView().getBoardDto().getBoardId() != null) {
		enterBoardNameView.showCancelButton();
	    } else {
		enterBoardNameView.hideCancelButton();
	    }

	    main.getBoard().getBoardHeaderHLayout().hide();
	    main.getBoard().getWhiteBoardView().showEnterBoardNameView();
	    main.getBoard().getNewKanbanButton().hide();
	    main.getFooter().hideBoardContactTileGrid();
	    main.getFooter().hideBoardHistoryListGrid();
	    main.getAdminPanel().getNewBoardButton().hide();
	} else {
	    main.getBoard().getWhiteBoardView().hideEnterBoardNameView();
	    main.getFooter().showBoardContactTileGrid();
	    main.getFooter().showBoardHistoryListGrid();
	    main.getBoard().getCurrentBoardNameLabel().setContents(RootPanel.getCurrentBoardDto().getBoardName());
	    main.getBoard().getBoardHeaderHLayout().show();
	    main.getAdminPanel().getNewBoardButton().show();
	}
    }

    public static BoardDto getCurrentBoardDto() {
	return main.getBoard().getWhiteBoardView().getBoardDto();
    }

    public static void activateEditKanbanMode(boolean isEditMode) {
	main.getBoard().setKanbanEditMode(isEditMode);
    }

    public static void activateEditKanbanMode(boolean isEditMode, KanbanView kanbanView) {
	main.getBoard().setKanbanEditMode(isEditMode, kanbanView);
    }

    public static boolean isEditMode() {
	return editMode;
    }

    public static boolean defaultBoardExists() {
	return main.getBoard().getWhiteBoardView().getBoardDto().getBoardId() != null;
    }

}
